import React, { Component } from 'react';

import {Table, InputNumber} from 'antd';

const MAX = 1000;

const SHOP = 100;



class B15 extends Component {

    state = {}

    getColums = (shops) => {

        let opts = [{
            title: '商品名',
            dataIndex: 'itemName', // name
            key: 'itemName',
            width: 120
        }, {
            title: '数量',
            dataIndex: 'count', // name
            key: 'count',
            width: 120
        }]

        shops.forEach(val=> {

            let name = `${val.name}采购数量`;
            let key = `_shopCount_${val.id}`;

            opts.push({
                title: name,
                dataIndex: key,
                key: key,
                width: 85,
                render: (val, record)=> {
                    return '';
                    // return <span>{val}</span>
                    // return (
                    //     <InputNumber
                    //         style={{width: '70px'}}
                    //         min={ 0 }
                    //         precision = {3}
                    //         value = {val}
                    //     />
                    // )
                }
            })
        })

        return opts;
    }

    getList = (list, shops)=> {
        list.forEach(val=> {
            shops.forEach(shop=> {
                val['_shopCount_' + shop.id] = shop.id;
            })
        })

        return list;

    }

    componentWillMount() {

        let list = new Array(MAX).fill(0).map((val, index)=> ({itemName: 'test' + index, count: index, id: index}));
        let shop = new Array(SHOP).fill(0).map((val, index)=> ({name: 'shop' + index, id: index}));

        this.state.list = this.getList(list, shop);

        this.columns = this.getColums(shop);

    }

    render() {

        let {list} = this.state;

        return (
            <Table
                scroll = {{y: 500}}
                rowKey = {(val)=> val.id}
                dataSource = {list}
                columns = {this.columns}
                pagination={false}
                bordered={true}
            />
        )
    }
}

export default B15;